﻿using IdentityModel;
using IdentityServer4;
using IdentityServer4.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Cms.Core.IdentityServer4.Model
{
    public static class Config
    {

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<IdentityResource> GetIdentityResources()
        {
          return new IdentityResource[]
          {
                new IdentityResources.OpenId(),
                new IdentityResources.Profile(),
               new IdentityResource("roles", "角色", new List<string> { JwtClaimTypes.Role }),
          };
        }

        public static IEnumerable<ApiResource> GetApiResources()
        {
            return new ApiResource[] {
                new ApiResource("cms.Core.Admin","Cms.Core.Admin后台管理系统")
                {
                         UserClaims = { JwtClaimTypes.Name, JwtClaimTypes.Role }
                }
          
            };
        }

        public static IEnumerable<Client> GetClients()
        {
            return new[]{
                     new Client{
                    ClientId="cms.admin vue",
                    ClientName="Cms Admin Vue前端",
                    AllowedGrantTypes=GrantTypes.Implicit,
                    AllowAccessTokensViaBrowser=true,

                    RedirectUris={

                        "http://localhost:8080/signin-oidc", 
                        "http://localhost:8080/redirect-silentrenew" 
                    },
                    PostLogoutRedirectUris={ "http://localhost:8080"

                    },
                    AllowedCorsOrigins={ "http://localhost:8080" },
                    AlwaysIncludeUserClaimsInIdToken=true,
                    AccessTokenLifetime=60*10,
                    RequireConsent=false,
                    //SlidingRefreshTokenLifetime=60*10,
                    AllowOfflineAccess=true,
                    AllowedScopes = { "cms.Core.Admin",
                           IdentityServerConstants.StandardScopes.OpenId,
                           IdentityServerConstants.StandardScopes.Profile,
                           //IdentityServerConstants.StandardScopes.OfflineAccess,
                         }
                }

            };
        }
    }
}
